﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;

namespace FinWeb3.Models.Helpers
{
    public static class HtmlExtensions
    {
        public static IEnumerable<SelectListItem> ToBankSelectList(
            this IList<Bank> banks, int? selectedBankId)
        {
            var bankList = banks.ToList();
            bankList.Insert(0, new Bank() { Id = 0, Name = "<Nenhum>" });

            var list = from bank in bankList
                       select new SelectListItem
                       {
                           Text = bank.Name,
                           Value = bank.Id.ToString(),
                           Selected = selectedBankId.HasValue ? bank.Id == selectedBankId.Value : false
                       };

            return list;
        }
    }
}
